package com.example.canteen.controller;

import com.example.canteen.Response;
import com.example.canteen.dto.PrivateRoomDTO;
import com.example.canteen.service.PrivateRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

@RestController
@RequestMapping("/privateRoom")
public class PrivateRoomController {
    @Autowired
    PrivateRoomService privateRoomService;

    @PostMapping("/all")
    Response<Set<PrivateRoomDTO>> getAllPrivateRooms() {
        return Response.newSuccess(privateRoomService.getAllPrivateRooms());
    }

    @PostMapping("/add")
    Response<Long> addPrivateRoom(@RequestBody PrivateRoomDTO privateRoomDTO) {
        return Response.newSuccess(privateRoomService.addPrivateRoom(privateRoomDTO));
    }

    @PostMapping("/update")
    Response<PrivateRoomDTO> updatePrivateRoomByName(@RequestBody PrivateRoomDTO privateRoomDTO) {
        return Response.newSuccess(privateRoomService.updatePrivateRoom(privateRoomDTO.getOldName(), privateRoomDTO.getName()));
    }
}
